using System;
using System.Collections.Generic;
using GreenTea.Utils;
using GreenTea.OQL;
using GreenTea.DAO;

namespace ByteCore.FerryBooking.Core
{
     partial class FareType
     {
         public string FullName
         {
             get
             {
                 return this.Category.CategoryName + " - " + this.FareTypeName + "(" + this.FareTypeDescription + ")";
             }
         }

         public FareTypeList GetFareTypeList(int operatorId, int fareCategoryId)
         {
             OQL oql = new OQL(typeof(FareType));
             if (operatorId != 0)
                 oql.AddCondition(Condition.Eq(FareType.Properties.OperatorId, operatorId));
             if (fareCategoryId != 0)
                 oql.AddCondition(Condition.Eq(FareType.Properties.CategoryId, fareCategoryId));

             return new FareType().GetList(oql);
         }


         public string FullFareTypeName
         {
             get 
             {
                 return this.FareTypeName + "(" + this.FareTypeDescription + ")";
             }
         }

         public static FareType GetFareTypeByValue(int operatorId, int categoryId, string fareTypeName, string fareTypeDesc)
         {
             OQL oql = new OQL(typeof(FareType));
             if (string.IsNullOrEmpty(fareTypeName) || string.IsNullOrEmpty(fareTypeDesc) || operatorId <= 0 || categoryId <= 0)
                 return null;

             oql.AddCondition(Condition.Eq(FareType.Properties.OperatorId, operatorId));
             oql.AddCondition(Condition.Eq(FareType.Properties.CategoryId, categoryId));
             oql.AddCondition(Condition.Eq(FareType.Properties.FareTypeName, fareTypeName));
             oql.AddCondition(Condition.Eq(FareType.Properties.FareTypeDescription, fareTypeDesc));

             FareTypeList list = new FareType().GetList(oql);
             if (list.Count == 1)
                 return list[0];
             else if (list.Count > 1)
                 throw new Exception("Duplicate Fare Type Found");
             else
                 return null;
         }

         public static void DoInsert(FareType fareType)
         {
             fareType.Create();
         }

         public IList<FareType> GetAccommodationTypeBySchedule(int scheduleId)
         {
             IList<FareType> ftList = new List<FareType>();
             Schedule schedule = new Schedule().GetById(scheduleId, false);
             Vessel vessel = new Vessel().GetById(schedule.VesselId.Value, false);
             ftList = vessel.FareTypes;
             return ftList;
         }
     }
}
